//
//  YSBRechargeWayView.m
//  YSBEmployer
//
//  Created by YSB_HJY on 2019/7/10.
//  Copyright © 2019 ysb. All rights reserved.
//  去除枚举
//


#import "YSBRechargeWayView.h"
#import "YSBChooseCareerViewController.h"


@interface YSBChooseCareerViewController ()

@property (nonatomic, strong) NSMutableArray *allDataSource;


@end


@implementation YSBChooseCareerViewController

- (NSMutableArray *)allDataSource{
    if (!_allDataSource) {
        _allDataSource = [[NSMutableArray alloc] init];
    }
    return _allDataSource;
}


- (void)filtrateView:(RHFiltrateView *)filtrateView didSelectAtIndexPath:(NSIndexPath *)indexPath {
        
    if (indexPath.section == 0 || !self.isComeFromeOffline) {
        YSBLabelModel *model = self.dataSource[indexPath.section][indexPath.row];
        self.myChooseCareer = model.name;
        self.cid = model.ID;
    }
    else{
        //获取所有数组里的元素
        [self.allDataSource removeAllObjects];
        if (self.dataSource.count > 1) {
            [self.allDataSource addObjectsFromArray:self.dataSource[0]];
            [self.allDataSource addObjectsFromArray:self.dataSource[1]];
        }
        
        YSBLabelModel *model = self.allDataSource[indexPath.row];
        self.myChooseCareer = model.name;
        self.cid = model.ID;
    }
}

@end



@interface YSBRechargeWayView ()

@property (strong, nonatomic) UIView *mainView;

@property (strong, nonatomic) UIView *titleView;
@property (strong, nonatomic) UIButton *cancelBtn;

@property (strong, nonatomic) UIView *wechatView;
@property (strong, nonatomic) UIImageView *wechatImageView;
@property (strong, nonatomic) UILabel *wechatLabel;

@property (strong, nonatomic) UIView *AliView;
@property (strong, nonatomic) UIImageView *aliImageView;
@property (strong, nonatomic) UILabel *aliLabel;

@property (strong, nonatomic) UIView *offlineView;
@property (strong, nonatomic) UIImageView *offlineImageView;
@property (strong, nonatomic) UILabel *offlineLabel;


@end


@implementation YSBRechargeWayView

- (instancetype)init {
    
    CGRect fr = CGRectMake(0, [[UIScreen mainScreen] bounds].size.height, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height);
    
    if (self = [super initWithFrame:fr]) {

        self.frame = fr;
        self.backgroundColor = [UIColor colorWithRed:(0)/255.0 green:(0)/255.0 blue:(0)/255.0 alpha:0.5];
        
        [self prepareSubViews];
        [self setupSubViews];
        
    }
    return self;
}


- (void)setupSubViews {
    
    [self addSubview:self.mainView];

    [self.mainView addSubview:self.titleView];
    [self.titleView addSubview:self.titleLabel];
    [self.mainView addSubview:self.cancelBtn];
    
    
    [self.mainView addSubview:self.AliView];
    [self.AliView addSubview:self.aliImageView];
    [self.AliView addSubview:self.aliLabel];

    
    [self.mainView addSubview:self.offlineView];
    [self.offlineView addSubview:self.offlineImageView];
    [self.offlineView addSubview:self.offlineLabel];
    
    
    [self.mainView addSubview:self.wechatView];
    [self.wechatView addSubview:self.wechatImageView];
    [self.wechatView addSubview:self.wechatLabel];

    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(cancelAction)];
    [self addGestureRecognizer:tap];

}


- (void)prepareSubViews {
    
    CGFloat allWidth = [[UIScreen mainScreen] bounds].size.width;

    CGFloat dHeight = [[UIScreen mainScreen] bounds].size.height * 1.0 / 667.0;
    CGFloat tHeight = ((60 * dHeight) - 50) * 0.5;
    CGFloat lHeight = ((60 * dHeight) - 20) * 0.5;

    
    self.titleView.frame = CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, 55 * dHeight);
    self.titleLabel.center = self.titleView.center;
    self.titleLabel.frame = CGRectMake(0, 0, allWidth, 55 * dHeight);
    self.cancelBtn.centerY = self.titleLabel.centerY;
    self.cancelBtn.frame = CGRectMake(allWidth - 65, 0, 50, 55 * dHeight);
    
    //支付宝支付
    self.AliView.frame = CGRectMake(0, 55 * dHeight + 1, allWidth, 60 * dHeight);
    self.aliImageView.frame = CGRectMake(15, tHeight, 50, 50);
    self.aliLabel.frame = CGRectMake(80, lHeight, 80, 20);

    //线下支付
    self.offlineView.frame = CGRectMake(0, (60 * dHeight + 1 + 55 * dHeight + 1), allWidth, 60 * dHeight);
    self.offlineImageView.frame = CGRectMake(15, tHeight, 50, 50);
    self.offlineLabel.frame = CGRectMake(80, lHeight, 80, 20);
    
    //微信支付
    self.wechatView.frame = CGRectMake(0, (60 * dHeight + 1) * 2 + (55 * dHeight + 1), allWidth, 60 * dHeight);
    self.wechatImageView.frame = CGRectMake(15, tHeight, 50, 50);
    self.wechatLabel.frame = CGRectMake(80, lHeight, 80, 20);
    
}


#pragma mark - Action
- (void)cancelAction {
    [self dismiss];
}

- (void)aliAction {
    _selectRechargeWay(4);
    [self dismiss];
}

- (void)wechatAction {
    _selectRechargeWay(3);
    [self dismiss];
}

- (void)offlineAction {
    _selectRechargeWay(5);
    [self dismiss];
}

- (void)show{
    self.hidden = NO;
    [UIView animateWithDuration:0.2 animations:^{
        self.frame = CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height);
    }];
}

- (void)dismiss{
    [UIView animateWithDuration:0.2 animations:^{
        self.frame = CGRectMake(0, [[UIScreen mainScreen] bounds].size.height, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height);
    }completion:^(BOOL finished) {
        self.hidden = YES;
    }];
}

#pragma mark - 视图
- (UIView *)mainView{
    if (!_mainView) {
        CGFloat dHeight = [[UIScreen mainScreen] bounds].size.height * 1.0 / 667.0;

        _mainView = [[UIView alloc] initWithFrame:CGRectMake(0, [[UIScreen mainScreen] bounds].size.height - (235 * dHeight) - 34, [[UIScreen mainScreen] bounds].size.width, (235 * dHeight) + 34)];
        _mainView.backgroundColor = [UIColor colorWithRed:(226)/255.0 green:(226)/255.0 blue:(226)/255.0 alpha:1];
    }
    return _mainView;
}

- (UIView *)titleView{
    if (!_titleView) {
        _titleView = [[UIView alloc] init];
        _titleView.backgroundColor = [UIColor whiteColor];
    }
    return _titleView;
}

- (UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.text = @"请选择充值方式";
        _titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightBold];
        _titleLabel.textColor = [UIColor colorWithRed:(34)/255.0 green:(34)/255.0 blue:(34)/255.0 alpha:1];
        _titleLabel.textAlignment = 1;
    }
    return _titleLabel;
}

- (UIButton *)cancelBtn{
    if (!_cancelBtn) {
        _cancelBtn = [[UIButton alloc] init];
        [_cancelBtn setTitleColor:[UIColor colorWithRed:(153)/255.0 green:(153)/255.0 blue:(153)/255.0 alpha:1] forState:UIControlStateNormal];
        [_cancelBtn setTitle:@"取消" forState:0];
        _cancelBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        [_cancelBtn addTarget:self action:@selector(cancelAction) forControlEvents:6];
    }
    return _cancelBtn;
}

- (UIView *)wechatView{
    if (!_wechatView) {
        _wechatView = [[UIView alloc] init];
        _wechatView.backgroundColor = [UIColor whiteColor];
        _wechatView.userInteractionEnabled = YES;
        UITapGestureRecognizer *wechatTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(wechatAction)];
        [_wechatView addGestureRecognizer:wechatTap];
        
    }
    return _wechatView;
}

- (UIImageView *)wechatImageView{
    if (!_wechatImageView) {
        _wechatImageView = [[UIImageView alloc] init];
        _wechatImageView.contentMode = 1;
        _wechatImageView.image = [UIImage imageNamed:@"mine_pay_wechat"];
    }
    return _wechatImageView;
}

- (UILabel *)wechatLabel{
    if (!_wechatLabel) {
        _wechatLabel = [[UILabel alloc] init];
        _wechatLabel.text = @"微信";
        _wechatLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightBold];
        _wechatLabel.textColor = [UIColor colorWithRed:(34)/255.0 green:(34)/255.0 blue:(34)/255.0 alpha:1];
    }
    return _wechatLabel;
}

- (UIView *)AliView{
    if (!_AliView) {
        _AliView = [[UIView alloc] init];
        _AliView.backgroundColor = [UIColor whiteColor];
        _AliView.userInteractionEnabled = YES;
        UITapGestureRecognizer *aliTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(aliAction)];
        [_AliView addGestureRecognizer:aliTap];
    }
    return _AliView;
}

- (UIImageView *)aliImageView{
    if (!_aliImageView) {
        _aliImageView = [[UIImageView alloc] init];
        _aliImageView.contentMode = UIViewContentModeScaleAspectFit;
        _aliImageView.image = [UIImage imageNamed:@"mine_pay_alipay"];
    }
    return _aliImageView;
}

- (UILabel *)aliLabel{
    if (!_aliLabel) {
        _aliLabel = [[UILabel alloc] init];
        _aliLabel.text = @"支付宝";
        _aliLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightBold];
        _aliLabel.textColor = [UIColor colorWithRed:(34)/255.0 green:(34)/255.0 blue:(34)/255.0 alpha:1];
    }
    return _aliLabel;
}


- (UIView *)offlineView{
    if (!_offlineView) {
        _offlineView = [[UIView alloc] init];
        _offlineView.backgroundColor = [UIColor whiteColor];
        _offlineView.userInteractionEnabled = YES;
        UITapGestureRecognizer *offlineTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(offlineAction)];
        [_offlineView addGestureRecognizer:offlineTap];
    }
    return _offlineView;
}


- (UIImageView *)offlineImageView{
    if (!_offlineImageView) {
        _offlineImageView = [[UIImageView alloc] init];
        _offlineImageView.contentMode = 1;
        _offlineImageView.image = [UIImage imageNamed:@"mine_pay_under"];
    }
    return _offlineImageView;
}

- (UILabel *)offlineLabel{
    if (!_offlineLabel) {
        _offlineLabel = [[UILabel alloc] init];
        _offlineLabel.text = @"线下支付";
        _offlineLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightBold];
        _offlineLabel.textColor = [UIColor colorWithRed:(34)/255.0 green:(34)/255.0 blue:(34)/255.0 alpha:1];
    }
    return _offlineLabel;
}



@end
